export BCAL_INSTALL_HNP_PATH=${HNP_PUBLIC_PATH}/bcal.org/bcal_2.4.0

sys_prefix=${PREFIX}
export PREFIX=${BCAL_INSTALL_HNP_PATH}
echo "${PREFIX}"

# 创建安装目录（确保目录存在）
mkdir -p ${BCAL_INSTALL_HNP_PATH}

make clean

# 编译时禁用 readline（使用 stub 实现）
make VERBOSE=1 CPPFLAGS="-UHAVE_READLINE" LDLIBS_READLINE="" || {
    echo "Error: make failed"
    exit 1
}
make install || {
    echo "Error: make install failed"
    exit 1
}

cp hnp.json ${BCAL_INSTALL_HNP_PATH}/ || {
    echo "Error: failed to copy hnp.json"
    exit 1
}

# 打包
if [ -d "${BCAL_INSTALL_HNP_PATH}" ]; then
    pushd ${BCAL_INSTALL_HNP_PATH}/../ > /dev/null
        ${HNP_TOOL} pack -i ${BCAL_INSTALL_HNP_PATH} -o ${ARCHIVE_PATH}/ || {
            echo "Error: HNP pack failed"
            popd > /dev/null
            export PREFIX=${sys_prefix}
            exit 1
        }
        tar -zvcf ${ARCHIVE_PATH}/ohos_bcal_2.4.0.tar.gz bcal_2.4.0/ || {
            echo "Error: tar failed"
            popd > /dev/null
            export PREFIX=${sys_prefix}
            exit 1
        }
    popd > /dev/null
else
    echo "Error: Installation directory does not exist: ${BCAL_INSTALL_HNP_PATH}"
    export PREFIX=${sys_prefix}
    exit 1
fi

export PREFIX=${sys_prefix}


